<?php 
namespace App\Libs\Helper;

class Vehicle extends \App\Libs\Base\BaseAction{
	protected static $api_key = 'LvuVYBsYvz1fcUikG38aM8fQCcVhQYUK';
	protected static $api_secret = '9FVxHb1nH5ZRGeg7xjCowfGqw0iKQ2Fp';

	/*
	* 行驶证验证
	*/
	public static function getVe($imgUrl = ''){

		//图片路径不对
		if (empty($imgUrl)) {
        	return \App\Libs\Views\Json::view(1, '图片路径不对', NULL);
		}

		//构建https请求
		$curl = curl_init();

		//请求网址
		$url = 'https://api-cn.faceplusplus.com/cardpp/v1/ocrvehiclelicense';
		
		curl_setopt($curl,CURLOPT_URL,$url);
		curl_setopt($curl,CURLOPT_HEADER,0);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

		curl_setopt($curl, CURLOPT_POST, 1);

		//构建发送的数据
		$data = [
		    'api_key'=>self::$api_key,
		    'api_secret'=>self::$api_secret,
		    'image_url'=>$imgUrl,
		];

		curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

		$data = curl_exec($curl);

		//关闭连接
		curl_close($curl);

		$data = json_decode($data,true)['cards'];

		if (isset($data['error_message'])) {
        	return \App\Libs\Views\Json::view(1, '请求失败', $data);
		}else{
	        return \App\Libs\Views\Json::view(0, '请求成功', $data);
		}
	}
}
